package com.dfrz.stockMarket.util;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;

/**
 * 工具类提供相关方法
 * @author Niko
 *
 */
public class UtilTools {
	public static String cstToHMS(Date cst,String accuracy) {
		SimpleDateFormat datefarmat =new SimpleDateFormat(accuracy);
		return datefarmat.format(cst).toString();
	}
	public static int daysOfTwo(Date fDate, Date oDate) {
	      LocalDate localDate = dateToLocalDate(fDate);
	      LocalDate localDate2 = dateToLocalDate(oDate);
	      return (int) (localDate2.toEpochDay()-localDate.toEpochDay());
	    }
	
	private static LocalDate dateToLocalDate(Date date) {
	    Instant instant = date.toInstant();
	    ZoneId zone = ZoneId.systemDefault();
	    LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
	    LocalDate localDate = localDateTime.toLocalDate();
	    
	    return localDate;
	}
	public Date tomorrow(Date today) {
		 Calendar calendar = Calendar.getInstance();
		 calendar.setTime(today);
		 calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
		 return calendar.getTime();
		 }
}
